library(knitr)
library(dplyr)
library(tidyverse)
library(ggplot2)
library(gridExtra)
library(magrittr)
library(plotly)
library(ggpubr)
library(patchwork)

0.1 Importing Data

df <- read.csv("Bidit_Life_data_tracking.csv",header = T, stringsAsFactors = T )
q <- table(df$Focus.Level..1.worst.5.best.,df$Meditation)
q_prop <- round(prop.table(q,margin = 2),2)*100
p <- addmargins(q)
rownames(p) <- c("<=10min","10 to 30 mins","30 to 60 mins","60 to 90 mins",">90 mins","Sum")
t <- as.matrix(p)
z <- data.frame(q_prop)
colnames(z) <- c("Focus_Level","Meditation_Status","Count")

fig1 <- plot_ly(
  type = 'table',
  header = list(
    values = c("<b>Focussed Time</b>", "<b>Meditation:No</b>","<b>Meditation:Yes</b>","<b>Sum</b>"),
  align = c('left', rep('center', ncol(t))),
  line = list(width = 1, color = 'black'),
  fill = list(color = 'rgb(235, 100, 230)'),
  font = list(family = "Arial", size = 14, color = "white")
  ),
  cells = list(
    values = rbind(
      rownames(t), 
      t(as.matrix(unname(t)))
    ),
    align = c('left', rep('center', ncol(t))),
    line = list(color = "black", width = 1),
    fill = list(color = c('rgb(235, 193, 238)', 'rgba(228, 222, 249, 0.65)')),
    font = list(family = "Arial", size = 12, color = c("black"))
  ))

fig1
plot_1 <-ggplot(z, aes(fill=Meditation_Status, y=Count, x=Focus_Level)) +
  geom_bar(position="dodge", stat="identity",colour="black")+theme_minimal() + geom_text(aes(label = paste(Count,"%",sep = "")), fontface = "bold", vjust = 1.5, position = position_dodge(0.9), size = 4)+scale_x_discrete(labels=c("<=10 mins","10 to 30 mins","30 to 60 mins","60 to 90 mins",">90 mins"))+xlab("Focus Time")+ylab("Percentage")+labs(title="EFFECT OF MEDITATION ON FOCUS TIME",caption = "Data Source:Bidit Personal Notion Database",tag = "Figure-1",fill="Meditation Done")+coord_flip()
fig2 <- ggplotly(plot_1)
fig2

Meditation on Focus Time